package com.mygdx.game;

import com.badlogic.gdx.Game;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.physics.box2d.Body;
import com.badlogic.gdx.physics.box2d.BodyDef;
import com.badlogic.gdx.physics.box2d.Box2DDebugRenderer;
import com.badlogic.gdx.physics.box2d.CircleShape;
import com.badlogic.gdx.physics.box2d.World;

/**
 * Created by 80002023 on 2016/8/5.
 */
public class Box2DTest2 extends Game {

    OrthographicCamera camera;

    Box2DDebugRenderer renderer;// 测试用绘制器

    World world;

    @Override
    public void create() {
        camera = new OrthographicCamera(48, 32);
        camera.position.set(0, 15, 0);

        renderer = new Box2DDebugRenderer();

        world = new World(new Vector2(0, -0.98f), true);// 一般标准重力场

        BodyDef bodyDef = new BodyDef();//声明物体定义
        bodyDef.position.set(2, 30);
        bodyDef.type = BodyDef.BodyType.DynamicBody;

        Body body = world.createBody(bodyDef);//通过world创建一个物体
        CircleShape circleShape = new CircleShape();//创建一个形状（圆）
        circleShape.setRadius(1f);
        body.createFixture(circleShape, 1f);
    }

    @Override
    public void render() {
        world.step(Gdx.app.getGraphics().getDeltaTime(), 3, 3);
        Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
        camera.update();

//        world.getContactList();

        renderer.render(world, camera.combined);
    }

    @Override
    public void dispose() {
        renderer.dispose();
        world.dispose();
    }
}
